﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Animal
{
    protected string Name;
    public Animal(string name)
    {
        this.Name = name;
    }
    public virtual void Run()
    {

    }
}
public class Cat : Animal
{
    public Action actions;//发布者
    public Cat(string name) : base(name)
    {

    }
    public void Coming(/*Animal mouse1, Animal mouse2, Animal mouse3*/)
    {
        Debug.Log(Name + "来了");
        //mouse1.Run();
        //mouse2.Run();
        //mouse3.Run();
        
        if (actions!=null)
        {
            actions();
        }
        this.Run();
    }
    public override void Run()
    {
        Debug.Log(Name + "开始追");
    }
}
public class Mouse : Animal
{
    public Mouse(string name,Cat cat) : base(name)
    {
        cat.actions += this.Run;//订阅者

    }
    public override void Run()
    {
        Debug.Log(Name + "逃跑");
    }
}
#region MyRegion


//public class Mouse2 : Animal
//{
//    public Mouse2(string name) : base(name)
//    {

//    }
//    public override void Run()
//    {
//        Debug.Log(Name + "逃跑");
//    }
//}
//public class Mouse3 : Animal
//{
//    public Mouse3(string name) : base(name)
//    {

//    }
//    public override void Run()
//    {
//        Debug.Log(Name + "逃跑");
//    }
//}
#endregion
public class Visit : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Cat cat = new Cat("大猫");

        Animal mouse1 = new Mouse("mouse1",cat);
        Animal mouse2 = new Mouse("mouse2", cat);
        Animal mouse3 = new Mouse("mouse3", cat);
        //cat.Coming(mouse1, mouse2, mouse3);
        cat.Coming();
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
